package com.lincoln.framework.interfaces;

import com.lincoln.framework.exception.ExecuteException;
import org.slf4j.Logger;

/**
 * 普通的执行器
 *
 * @author lincoln
 */
public abstract class BaseExecute {
    /**
     * 服务器发过去的指令头
     *
     * @return
     */
    public abstract byte[] getServerCmd();

    /**
     * 生成serverCmd的key
     *
     * @return
     */
    public String getServerCmdText() {
        StringBuilder res = new StringBuilder();
        for (byte b : getServerCmd()) {
            res.append(Integer.toHexString(b));
        }
        return res.toString();
    }

    /**
     * 客户端发过来的指令头
     *
     * @return
     */
    public abstract byte[] getClientCmd();

    /**
     * 生成clientCmd的key
     *
     * @return
     */
    public String getClientCmdText() {
        StringBuilder res = new StringBuilder();
        for (byte b : getClientCmd()) {
            res.append(Integer.toHexString(b));
        }
        return res.toString();
    }

    /**
     * 日志
     *
     * @return
     */
    public abstract Logger getLogger();

    /**
     * 执行解析+回调任务
     *
     * @param protocol
     * @return
     */
    public abstract boolean execute(BaseProtocol protocol) throws ExecuteException;
}
